package de.bwv.javaproject.FunnyTokens.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JTextField;

import de.bwv.javaproject.FunnyTokens.utils.EditorUtils;
import de.java.swing.extension.controller.ExtendedMouseAdapter;
import de.java.swing.extension.ui.ExtendedPanel;
import de.java.swing.extension.ui.Toolbar;
import de.java.swing.extension.ui.ToolbarItem;

/**
 * Das Panel aus dem im Spiel der Spielstand gespeichert werden kann.
 * 
 * @author Patrick Haas
 * 
 */
public class SaveCardPanel extends ExtendedPanel implements EditorUtils {

	private static final long serialVersionUID = -9180666118021305309L;

	private ExtendedPanel northPane;

	private Toolbar toolbar;

	private ToolbarItem toolbarItemSaveCard;

	private ToolbarItem toolbarItemCancel;

	private JTextField tfName;

	/**
	 * Konstruktor.
	 * 
	 */
	public SaveCardPanel() {
		initialize();
	}

	private void initialize() {
		this.setLayout(new BorderLayout());

		northPane = new ExtendedPanel();
		northPane.setLayout(new BorderLayout());

		this.toolbar = new Toolbar();
		this.toolbar.setPreferredSize(new Dimension(0, 30));
		this.toolbar.setBackground(new Color(61, 34, 7));
		northPane.add(BorderLayout.NORTH, toolbar);

		this.toolbarItemSaveCard = new ToolbarItem("Speichern", new ImageIcon("images\\toolbar\\save.png"));
		this.toolbarItemSaveCard.setToolTipText("Karte speichern");
		this.toolbarItemSaveCard.setMouseOutColor(Color.GRAY);
		this.toolbar.addItem(toolbarItemSaveCard);

		this.toolbarItemCancel = new ToolbarItem("Abbrechen", new ImageIcon("images\\toolbar\\cancel.png"));
		this.toolbarItemCancel.setToolTipText("Abbrechen");
		this.toolbarItemCancel.setMouseOutColor(Color.GRAY);
		this.toolbar.addItem(toolbarItemCancel);

		this.tfName = new JTextField(TITLE_NAME_OF_CARD);
		this.tfName.setPreferredSize(new Dimension(0, 25));
		this.tfName.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
		this.tfName.addMouseListener(new ExtendedMouseAdapter() {
			@Override
			public void execute() {
				if (tfName.getText().equals(TITLE_NAME_OF_CARD)) {
					tfName.setText("");
				}
			}
		});
		northPane.add(BorderLayout.SOUTH, tfName);
		this.add(BorderLayout.NORTH, northPane);
	}

	/**
	 * @return the toolbarItemSaveCard
	 */
	public ToolbarItem getToolbarItemSaveCard() {
		return toolbarItemSaveCard;
	}

	/**
	 * @return the toolbarItemCancel
	 */
	public ToolbarItem getToolbarItemCancel() {
		return toolbarItemCancel;
	}

	/**
	 * @return the tfName
	 */
	public JTextField getTfName() {
		return tfName;
	}

}
